/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package JavaAssignment;

import java.io.*;
import java.util.*;

/**
 *
 * @author Ishaan
 */
public class TRCollection implements Serializable {

    private LinkList TRList;
    private int currRec;
    private int noOfElement = 0;

    public TRCollection() {

        TRList = new LinkList();
        currRec = 0;
    }

    public int getNumOfRec() {
        return TRList.getNoOfElement();
    }


    public Object get(int index) throws IndexOutOfBoundsException {

    if (index >= 0 && index < noOfElement) {
      ListNode currnode = find(index);
      Object data = currnode.getData();
      return data;
    }
    else {
      throw new IndexOutOfBoundsException(
          "index out of bounds exception on get");
    }

  }

    public void addLastRec(TransactionRecord e) {
        TRList.addLast(e);
    }

    public void addRec(int i, TransactionRecord e) {
        TRList.add(currRec, e);
    }

    public int getNext() {
        if (currRec == TRList.getNoOfElement() - 1) {
            return TRList.getNoOfElement() - 1;
        } else {
            return ++currRec;
        }
    }

    public int getPrev() {
        if (currRec == 0) {
            return currRec;
        } else {

            return --currRec;
        }
    }

    public int getFirst() {
        currRec = 0;
        return currRec;
    }

    public int getLast() {
        currRec = TRList.getNoOfElement() - 1;
        return currRec;
    }
}


